<!-- pages/return/index.vue -->  
<template>  
  <view class="page-container">  
    <view class="dialog-container">  
      <view class="dialog-body">  
        <view class="button-group">  
          <button class="action-button" @click="returnTo('上级')">退回上级</button>  
          <button class="action-button" v-if="tuihuiFrom=='samplingMonitoring'" @click="returnTo('下级')">退回下级</button>  
        </view>  
      </view>  
      </view>  
    </view>  
  </view>  
</template>  

<script>  
import { rejectTask } from "@/api/mobilebusiness";  

export default {  
  data() {  
    return {  
      selectedOption: "", // 当前选项  
	  tuihuiFrom: '',
	  tuihui : {
	          tuihuiModel: '',
	          taskId : ''
	        },
    };  
  },  
   onLoad(options) {  
      if (options) {  
        this.tuihui.taskId = options.taskId;  
		this.tuihuiFrom = options.tuihuiFrom; 
      }  
	  console.log("接收到的任务ID:", this.tuihui);  
	  console.log("接收到的来源:", this.tuihuiFrom);  
    },
  methods: {  
    
    returnTo(option) {  
      this.selectedOption = option; // 设置当前选项  
      console.log(`选择的退回按钮: ${this.selectedOption}`);  
	  this.confirmReturn();
    },  
    confirmReturn() {  
      if (this.selectedOption) {  
		if(this.tuihuiFrom=='taskExamine'){
			this.tuihui.tuihuiModel = '0';
		}else if (this.tuihuiFrom=='samplingMonitoring') {
			if(this.selectedOption === "上级" ){
				this.tuihui.tuihuiModel = '1';
			}else{
				this.tuihui.tuihuiModel = '6';
			}
		}else if (this.tuihuiFrom=='samplemanagement') {
			this.tuihui.tuihuiModel = '2';
		}else if (this.tuihuiFrom=='experimentalAnalysis') {
			this.tuihui.tuihuiModel = '3';
		}else if (this.tuihuiFrom=='monitoringReport') {
			this.tuihui.tuihuiModel = '4';
		}
        console.log(this.tuihui);  
		
        // 调用退回接口  
        rejectTask( this.tuihui )  
          .then((response) => {  
            uni.showToast({  
              title: "退回完成",  
              icon: "success",  
            });  
          })  
          .catch((error) => {  
            console.error("退回失败", error);  
            uni.showToast({  
              title: "退回失败，请重试",  
              icon: "none",  
            });  
          });  
		   uni.navigateBack(); // 退回成功后返回上一页  
      }  
    },  
  },  
};  
</script>  

<style scoped>  
.page-container {  
  padding: 20px;  
  background-color: #fff;  
}  

.dialog-body {  
  padding: 20px;  
  text-align: center; /* Center align buttons */  
}  

.button-group {  
  display: flex;  
  justify-content: space-around; /* Distribute buttons evenly */  
}  

.action-button {  
  flex: 1; /* Each button takes equal space */  
  height: 45px;  
  font-size: 16px;  
  margin: 10px; /* Margin for spacing */  
  border-radius: 4px;  
  background-color: #007aff; /* Button color */  
  color: #ffffff; /* Text color */  
  border: none; /* Remove border */  
}  

.dialog-footer {  
  display: flex;  
  justify-content: space-between;  
  padding: 10px 0;  
}  

.dialog-button {  
  flex: 1;  
  height: 45px;  
  font-size: 16px;  
  border-radius: 4px;  
}  

.cancel {  
  background-color: #ffffff;  
  border: 1px solid #ddd;  
  color: #333;  
}  

.confirm {  
  background-color: #007aff; /* 确认按钮颜色 */  
  color: #ffffff;  
  margin-left: 10px; /* 设置间距 */  
}  
</style>